<template>
  <div class="content-block">
    <div class="info-head">
      <span>{{ title }}</span>
    </div>
    <div class="info-content padding" style="padding-top: 20px">
      <div class="flex justify-between overview">
        <div
          class="overview-item"
          v-for="(item, index) in data"
          :key="index"
          :style="{ backgroundColor: themeColor }"
        >
          <span class="item-icon" v-if="item.icon">
            <svg-icon :name="item.icon"></svg-icon>
          </span>
          <h2 class="item-label">{{ item.energyName }}</h2>
          <div class="item-main">
            <span class="item-number">{{ item.data | formatNumber }}</span>
            <span class="item-unit">{{ item.energyUnit }}</span>
          </div>
          <p class="item-content">
            同比：{{ item.yoy }}%
            <br />
            环比：{{ item.mom }}%
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'grid-item-one',
  props: {
    title: String,
    data: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  computed: {
    themeColor() {
      return this.$store.state.user.theme;
    }
  },
  filters: {
    formatNumber(value) {
      return Number(value) ? Number(value).toLocaleString() : '-';
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/style/variable.scss';

.overview-item {
  flex: 1;
  border-radius: 4px;
  padding: 30px 20px;
  color: white;
  position: relative;
  overflow: hidden;
}

.item-label {
  font-size: 22px;
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 2rem;
}

.item-number {
  font-size: 20px;
  color: orange;
  margin-right: 5px;
}

.item-icon {
  position: absolute;
  right: 20px;
  bottom: 10px;
  font-size: 3vw;
  color: white;
  opacity: 0.8;
}
</style>
